package com.baozun.houji.me.viewmodel

import androidx.lifecycle.MutableLiveData
import com.baozhun.mall.common.model.bean.*
import com.baozhun.mall.common.network.mCommonApiService
import com.baozhun.mall.common.util.ColorUtil
import com.baozun.houji.me.R
import com.baozun.houji.me.network.mMeApiService
import com.blankj.utilcode.util.ToastUtils
import me.hgj.jetpackmvvm.base.viewmodel.BaseViewModel
import me.hgj.jetpackmvvm.ext.request
import me.hgj.jetpackmvvm.ext.requestNoCheck

/**
 *  @Title：CollectionViewModel
 * @Description：
 * @Author：xuefeng.zhu
 * @Since：2022/11/4
 * @Version：1.0.0
 */
class CollectionViewModel : BaseViewModel() {
    private var mCollectionCurrentPage = 1
    var mCollectionList = MutableLiveData<ApiPagerResponse<ArrayList<GoodsInfoBean>>>()

    /**
     * 获取收藏列表数据
     */
    fun getCollectionList(isRefresh: Boolean? = true, goodsType: String) {
        if (isRefresh == true) mCollectionCurrentPage = 1
        request({
            mMeApiService.getCollectionList(mCollectionCurrentPage, goodsType)
        }, {
            mCollectionList.value = it
            mCollectionCurrentPage += 1
        }, isShowDialog = false, showErrorMsg = false)
    }


    fun deleteCollect(goodsId: String, goodsType: String, deleteSuccessCallback: () -> Unit) {
        requestNoCheck({ mCommonApiService.cancelCollection(goodsId, goodsType) }, {
            if (it.isSuccess()) {
                deleteSuccessCallback.invoke()
            }
            ToastUtils.showShort(com.baozhun.mall.res.R.string.operation_success)
        }, isShowDialog = true)
    }
}